package com.znyj.servlet.dao;

import com.znyj.servlet.entity.ReportEntity;
import com.znyj.servlet.sqlHelper.SqlProvider;
import com.znyj.servlet.sqlHelper.SqlRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.List;


/**
 * Created by gaoliwei02 on 17/5/31.
 */

@Repository
public interface ReportDao {

    @Select("select order_id_a from cdb_report where device_id=#{deviceId}")
    public long getChannalAOrderId(@Param("deviceId") String deviceId);

    @Select("select order_id_b from cdb_report where device_id=#{deviceId}")
    public long getChannalBOrderId(@Param("deviceId") String deviceId);

    @Select("select * from cdb_report where device_id=#{deviceId}")
    public ReportEntity findByDeviceId(@Param("deviceId") String deviceId);

    @Select("select online_status from cdb_report where device_id=#{deviceId}")
    public String isDeviceIdOnline(@Param("deviceId") String deviceId);

    @SelectProvider(type = SqlProvider.class, method = "query")
    public List<ReportEntity> query(SqlRequest request);

    @SelectProvider(type = SqlProvider.class, method = "count")
    public int count(SqlRequest request);

    @Delete("delete from cdb_report where device_id=#{deviceId}")
    public int deleteByDeviceId(@Param("deviceId") String deviceId);

    @Update("update cdb_report set " +
            "order_create_time_a=#{orderCreateTimeA}," +
            "order_duration_sec_a=#{orderDurationSecA}," +
            "user_id_a=#{userIdA}," +
            "order_id_a=#{orderIdA}," +
            "order_create_time_b=#{orderCreateTimeB}," +
            "order_duration_sec_b=#{orderDurationSecB}," +
            "user_id_b=#{userIdB}," +
            "order_id_b=#{orderIdB} " +
            "where device_id=#{deviceId}")
    public int updateABInfo(@Param("deviceId") String deviceId,
                            @Param("orderCreateTimeA") Timestamp orderCreateTimeA,
                            @Param("orderDurationSecA") long orderDurationSecA,
                            @Param("userIdA") String userIdA,
                            @Param("orderIdA") long orderIdA,
                            @Param("orderCreateTimeB") Timestamp orderCreateTimeB,
                            @Param("orderDurationSecB") long orderDurationSecB,
                            @Param("userIdB") String userIdB,
                            @Param("orderIdB") long orderIdB
    );
}